<template>
<!-- 设计策划计划表管理 -->
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>
    <a-card :bordered="false" style="over-flow:scroll">
      <!-- <title-name title="设计策划计划表列表"></title-name> -->
      <div>
        <a-row>
          <a-col :md="24" :sm="19">
            <div class="table-operator">
              <a-row>
                <a-col :md="24" :sm="24">
                  <a-button type="primary"  @click="goAdd('add')" v-btnPermission="'ds_001_add_01'">新增设计策划计划表</a-button>
                </a-col>
              </a-row>
            </div>

            <div class="pub-table-select-count">
              <a-icon type="info-circle" theme="twoTone"/>
              <span style="margin-right: 12px">
                总设计策划计划表数：<span class="totalNum">{{total.total }} 个 </span> |
                待提交审核：<span class="totalNum">{{total.draftNum }} 个 </span> |
                签字中：<span class="totalNum">{{ total.signingNum }} 个 </span> |
                审核中：<span class="totalNum">{{ total.submittedNum }} 个 </span> |
                审核通过：<span class="totalNum">{{ total.passNum }} 个 </span> |
                审核不通过：<span class="totalNum">{{ total.rejectedNum }} 个 </span>
              </span>
            </div>
            <list-table
                    ref="table"
                    size="default"
                    rowKey="row.id"
                    :columns="columns"
                    :request="loadData"
                    :alert="true"
                    show-size-changer
                    show-quick-jumper
                    showPagination="auto">
              <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
              <span slot="action" slot-scope="text, record">
                <MoreButton>
                <a @click="handleSub(record,'view')" v-btnPermission="'ds_001_loo_02'">查看</a>
                  <a-divider v-if="record.statusCode=='0' || record.statusCode=='4'"  type="vertical"/>
                <a v-if="record.statusCode=='0' || record.statusCode=='4'" @click="handleEdit(record,'edit')" v-btnPermission="'ds_001_edi_03'">编辑</a>
                  <a-divider  v-if="record.statusCode != '0'"   type="vertical" v-btnPermission="'ds_001_moi_06'"/>
                <a v-if="record.statusCode != '0'"  @click="handleApproveDetail(record)" v-btnPermission="'ds_001_moi_06'">审批信息</a>
                </MoreButton>
              </span>
            </list-table>
          </a-col>
        </a-row>
      </div>

    </a-card>


    <a-modal
            title="签字"
            :visible="visible"
            :confirm-loading="confirmLoading"
            width="1000px"
            @ok="handleOk"
            @cancel="handleCancel">
      <title-name title="设计策划计划表"></title-name>
      <a-form>
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="分公司"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.branch" disabled  placeholder="请输入" />
            </a-form-model-item>
          </a-col>

          <a-col
                  :md="12" :sm="12">
            <a-form-model-item
                    label="项目名称"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.projectName" disabled  placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="项目编号"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.num" disabled  placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="项目设计管理类别"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.designType" disabled  placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="项目进场时间"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.inTime" disabled  placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="创建人"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.personName" disabled  placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="创建时间"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.time" disabled  placeholder="请输入" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
      <title-name title="计划项"></title-name>
        <a-table
                ref="table"
                rowKey="row.id"
                :columns="columns1"
                :pagination=false
                :data-source="tableData" >

          <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
          <span slot="action" slot-scope="text, record">
            <template>
            <!-- <a @click="handleSub(record,'view')">查看</a>
              <a-divider type="vertical"/> -->
            <a v-if="type=='add'||type=='edit'" @click="handleEdit(record)">编辑</a>
            </template>
          </span>
        </a-table>
    </a-modal>


        <!-- 审批详情 -->
        <ApprovalDetails
            :title="'审批详情'"
            :businessId="businessId"
            :visible="visibleApprove"
            @cancel="visibleApprove = false"
            @confirm="visibleApprove = false"
        />
  </base-breadcrumb>
</template>

<script>
  import Vue from 'vue'
  import { STable, Ellipsis } from '@/components'
  import { getPlotsPlanList  ,addEvaluateList,getEvaluateListTotal ,sign,getMattersByproject, getPlotsPlanListTotal ,addPlan ,getDetails} from '@/api/design/plotsPlan'
  import { getCompany } from '@/api/themeChoose/themeChoose'
  import  { getTypes} from '@/api/commons'
  import ApprovalDetails from '@/components/approvalDetails'
  import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
  import OrgTreeSelect from '@/components/OrgTreeSelect'
  const columns = [
    {
      title: '序号',
      width: '65px',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '项目名称',
      dataIndex: 'projectName'
    },
    {
      title: '项目编号',
      dataIndex: 'num',

    },
    {
      title: '分公司',
      dataIndex: 'branch',

    },
    {
      title: '项目设计管理类别',
      dataIndex: 'designType',
    },
    {
      title: '进场时间',
      dataIndex: 'inTime',
    },
    {
      title: '创建人',
      width: '100px',
      dataIndex: 'person',
    },
    {
      title: '创建时间',
      dataIndex: 'time',
    },
    {
      title: '状态 ',
      width: '110px',
      dataIndex: 'status',
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      scopedSlots: { customRender: 'action' }
    }
  ]
  const columns1 = [
    {
      title: '序号',
      width: '65px',
      dataIndex: 'serial',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '计划事项',
      dataIndex: 'matter'
    },
    {
      title: '计划时间',
      dataIndex: 'time',

    },
    {
      title: '责任人',
      width: '100px',
      dataIndex: 'person',

    },
    {
      title: '责任人员工编号',
      dataIndex: 'personNum',
    },
  ]
  export default {
    name:'a'+ Date.now(),
    components:{
      STable,
      ApprovalDetails
    },
    data(){
      this.columns = columns
      this.columns1 = columns1
      return{
        // 查询参数
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          return getPlotsPlanList(requestParameters)
            .then(res => {
              return res
            })
        },
        selectedRowKeys:'',
        selectedRows:'',
        confirmLoading:false,
        tableData:[],
        formAdd:{},
        businessId:'',
        visibleApprove:false,
        total:{},
        form:{
          name:'',
          status:''
        },
        visible:false,
        searchArr: [
          // 搜索框
          {
            name: '项目名称',
            value: 'projectName',
            type: 'input'
          },
          {
            name: '所属单位',
            valueKey: 'searchQuery',
            type: OrgTreeSelect,
          },
          //           {
          //   name: '分公司',
          //   valueKey: 'branchCompany',
          //   type: SelectSubCompany ,

          // },
          // {
          //   name: '分公司',
          //   type: 'select',
          //   value: 'branchCompany',
          //   data: []
          // },
          {
            name: '项目设计管理类别',
            value: 'designType',
            type: 'select',
            data:[]
          },
          {
            name: '项目编号',
            value: 'num',
            type: 'input'
          },
          {
            name: '状态',
            type: 'select',
            value: 'status',
            data: [
              {
                value: '0',
                label: '待提交审核'
              },
              {
                value: '1',
                label: '签字中'
              },
              {
                value: '2',
                label: '审核中'
              },
              {
                value: '3',
                label: '审核通过'
              },
              {
                value: '4',
                label: '审核不通过'
              },
            ]
          },
        ]
      }
    },
    computed: {
      // rowSelection() {
      //   return {
      //     selectedRowKeys: this.selectedRowKeys,
      //     selectedRows: this.selectedRows,   // 当前行所有数据
      //     onChange: this.onSelectChange
      //   }
      // }
    },
    created() {
      this.getPlotsPlanListTotal()
      const userInfo = Vue.getAcloudProvider().getUserInfo()
      // this.getCompanyList({orgIds:[userInfo.orgId], tagCodes:['BC']})
      this.getTypes()
    },
    methods:{
      // 分公司
      getCompanyList(params){
        getCompany(params).then(res=>{
          let companyList = []
          res.data.forEach(item=>{
            companyList.push({
              label:item.orgName,
              value:item.orgId
            })
          })
          this.searchArr[1].data = companyList
        })
      },
      handleApproveDetail(record){
        this.visibleApprove = true
        this.businessId = record.id
      },
      getTypes(){
        getTypes({type:'9'}).then(res=>{
          let list = []
          res.data.forEach(item=>{
            list.push({
              label:item.name,
              value:item.id
            })
          })
          list=list.splice(3,2)
          this.searchArr[2].data = list
        })
      },
      getPlotsPlanListTotal(){
        getPlotsPlanListTotal(this.queryParam).then((res)=>{
          this.total = res.data
        })
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        console.log(selectedRowKeys)
        console.log(selectedRows)
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      search(values){
        this.queryParam = values
        this.$refs.table.refresh(true)
        getPlotsPlanListTotal(this.queryParam ).then((res)=>{
          this.total = res.data
        })
      },
      goAdd(type){
        this.$router.push({
          path:"/project/design/add",
          query:{
            type:type
          }
        })
      },
      handleSub(record,type){
        this.$router.push({
          path:"/project/design/view",
          query:{
            id:record.id,
            type:type
          }
        })
      },
      handleEdit(record,type){
        this.$router.push({
          path:"/project/design/edit",
          query:{
            id:record.id,
            type:type
          }
        })
      },
      handleApprove(record,type){
        this.$router.push({
          path:"/project/design/approve",
          query:{
            id:record.id,
            type:type
          }
        })
      },
      handleOk(){
        this.visible = false
        this.formAdd.signatureCode = "123"
        this.formAdd.list = this.tableData
        sign(this.formAdd).then((res)=>{
          if(res.code=='200'){
            this.$refs.table.refresh(true)
            this.$message.success("新增成功")
          }
        })
      },
      handleCancel(){
        this.visible = false
      }
    }
  }
</script>

<style scoped>
  .input{
    width:100%
  }
  .notShow{
    display:none
  }
</style>
